package com.frxuexi.park2212.payment

import androidx.lifecycle.MutableLiveData
import com.frxuexi.lib_base.base.BaseViewModel
import com.frxuexi.lib_base.entity.BillBean
import com.frxuexi.lib_base.entity.BillBeanItem
import com.frxuexi.lib_base.entity.PayBean
import com.frxuexi.lib_base.entity.PayBeanItem
import com.frxuexi.lib_base.net.ApiService
import dagger.hilt.android.lifecycle.HiltViewModel
import retrofit2.http.Query
import javax.inject.Inject

@HiltViewModel
class PayViewModel  @Inject constructor(val apiService: ApiService):BaseViewModel(){
    val addPay = MutableLiveData<PayBeanItem>()

    val getPays=MutableLiveData<PayBean>()

    val pay=MutableLiveData<PayBeanItem>()

    val addBill = MutableLiveData<BillBeanItem>()

    val getBills= MutableLiveData<BillBean>()

    val getBillById= MutableLiveData<BillBeanItem>()

    fun addPay(item: PayBeanItem){
        httpRequest({apiService.addPayProject(toBody(item))},addPay::postValue)
    }

    fun getPays(uid:Int){
        httpRequest({apiService.getPayProjectsByUid(uid)},getPays::postValue)
    }

    fun pay(id: Int,actualAmount:Int,operator:String,paymentMethod:String,paymentTime:String){
        httpRequest({apiService.payProject(id, actualAmount, operator, paymentMethod, paymentTime)},pay::postValue)
    }

    fun addBill(item:BillBeanItem){
        httpRequest({apiService.addBill(toBody(item))},addBill::postValue)
    }

    fun getBills(pid:Int){
        httpRequest({apiService.getMybills(pid)},getBills::postValue)
    }

    fun getBillById(id:Int){
        httpRequest({apiService.getbillById(id)},getBillById::postValue)
    }
}